package com.yinxianren.main.study.spring.one;

import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@RestController
public class DemoDynamic {

    @Resource(name="dog")
    private IAnimal dog;

    @Resource(name="sheep")
    private IAnimal sheep;


    @RequestMapping("/dog")
    public String dogEat(){
        System.out.println("##############dog#############");
        dog.eat();
        return "dog";
    }

    @RequestMapping("/sheep")
    public String sheepEat(){
        System.out.println("##############sheep#############");
        sheep.eat();
        return "sheep";
    }
}

interface IAnimal{
    void eat();
}

@Service("dog")
class DogAnimal implements IAnimal{

    @Override
    public void eat() {
        System.out.println("dog have bone");
    }
}

@Service("sheep")
class SheepAnimal implements IAnimal{

    @Override
    public void eat() {
        System.out.println("sheep have grass");
    }
}